Add new GLib 0.14 variant types for metadata types
authorColin Walters <walters@verbum.org>
Mon, 2 Aug 2021 18:41:22 +0000 (14:41 -0400)
committerColin Walters <walters@verbum.org>
Fri, 6 May 2022 16:53:57 +0000 (12:53 -0400)
This way it's more convenient for downstream crates like ostree-rs-ext
to convert loaded variants.

TODO: Can we add a feature for the `gvariant` crate and expose via
that too?

rust-bindings/rust/src/core.rs [new file with mode: 0644]
rust-bindings/rust/src/lib.rs
rust-bindings/rust/tests/core/mod.rs [new file with mode: 0644]
rust-bindings/rust/tests/tests.rs

diff --git a/rust-bindings/rust/src/core.rs b/rust-bindings/rust/src/core.rs
new file mode 100644 (file)
index 0000000..616e112
--- /dev/null
@@ -0,0 +1,21 @@
+//! Hand written bindings for ostree-core.h
+
+use glib::VariantDict;
+
+/// The type of a commit object: `(a{sv}aya(say)sstayay)`
+pub type CommitVariantType = (
+    VariantDict,
+    Vec<u8>,
+    Vec<(String, Vec<u8>)>,
+    String,
+    String,
+    u64,
+    Vec<u8>,
+    Vec<u8>,
+);
+
+/// The type of a dirtree object: `(a(say)a(sayay))`
+pub type TreeVariantType = (Vec<(String, Vec<u8>)>, Vec<(String, Vec<u8>, Vec<u8>)>);
+
+/// The type of a directory metadata object: `(uuua(ayay))`
+pub type DirmetaVariantType = (u32, u32, u32, Vec<(Vec<u8>, Vec<u8>)>);
index 8b065dc7839d7d2ce7b5d0a16d48332c61617eec..9e7fa63175b5105142ba81875c2116be13e15ce6 100644 (file)
@@ -27,6 +27,9 @@ pub use crate::auto::*;
 // handwritten code
 mod checksum;
 pub use crate::checksum::*;
+mod core;
+pub use crate::core::*;
+
 #[cfg(any(feature = "v2018_6", feature = "dox"))]
 mod collection_ref;
 #[cfg(any(feature = "v2018_6", feature = "dox"))]
diff --git a/rust-bindings/rust/tests/core/mod.rs b/rust-bindings/rust/tests/core/mod.rs
new file mode 100644 (file)
index 0000000..7ac13cf
--- /dev/null
@@ -0,0 +1,13 @@
+use crate::util::*;
+use std::error::Error;
+
+#[test]
+fn variant_types() -> Result<(), Box<dyn Error>> {
+    let tr = TestRepo::new();
+    let commit_checksum = tr.test_commit("test");
+    let repo = &tr.repo;
+    let commit_v = repo.load_variant(ostree::ObjectType::Commit, commit_checksum.as_str())?;
+    let commit = commit_v.get::<ostree::CommitVariantType>().unwrap();
+    assert_eq!(commit.3, "Test Commit");
+    Ok(())
+}
index 9510133c4221f7f16551423419bd1bbce65e9af8..18076002b471e60e82cb615800304248fc93b351 100644 (file)
@@ -1,3 +1,4 @@
+mod core;
 mod functions;
 mod repo;
 #[cfg(feature = "v2020_2")]